<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<% String contextPath = request.getContextPath(); %>
<%@page import="common.*" %>
<%@ page import="java.util.*" %>
<%
	Customer user = (Customer)session.getAttribute("user");
	if(user == null || user.equals("null")) response.sendRedirect(request.getContextPath() +"/index.jsp");
	else{Cart cart = (Cart)session.getAttribute("cart");
	List<OrderItem> list = cart.getItems();
	int total_price = 0;
	String msg = (String)request.getAttribute("msg");
	if(msg == null) msg = "";
	
	ArrayList<Item> err = (ArrayList<Item>)request.getAttribute("err");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link href="<%= contextPath %>/css/style.css" rel="stylesheet" type="text/css" />
		<link href="<%= contextPath %>/css/sidemenu.css" rel="stylesheet" type="text/css" />
		<link href="<%= contextPath %>/css/msg.css" rel="stylesheet" type="text/css" />
		<title>カート</title>
		<script type="text/javascript">
			function changed() {
			//	location.href = "/itenVII/xxxxServlet?num=2&orders=4";
			}
		</script>
	</head>
	<body>
		<div id="wrapper">
			<div id="sidemenu"">
				<jsp:include page="sidemenu.jsp" flush="true"/>
			</div>
			<div id="contents">
				<div id="right">
					<div id="msg">
							<div id="search">
								現在のカートの中
							</div>
							<div id="error">
								<%= msg.replaceAll("\n", "<br />") %>
							</div>
						<div id="clear"></div>
					</div>
					<div id="tabl">
						<table border="1">
							<tr>
								<th>商品名</th>
								<th>商品コード</th>
								<th>規格</th>
								<th>売単価</th>
								<th>注文数</th>
							</tr>
							<% for(int i=0; i<list.size(); i++)
								{
									OrderItem oi = list.get(i);
									Item item = Item.find_by_code(oi.getItem_code());%>
							<tr>
								<td><%= item.getName() %></td>
								<td><%= item.getCode() %></td>
								<td><%= item.getSize() %></td>
								<td><%= item.getPrice() %>円</td>
								<td>
									<form action="<%= contextPath %>/orderCus/CartEditServlet" method="post" style="display:inline;">
										<input type="hidden" name="num" value="<%= i+1 %>" />
										<select name="orders" onChange="changed();">
											<option selected="selected" value ="<%= oi.getOrders() %>"><%= oi.getOrders() %></option>
											<% for(int j=0; j<item.getStock(); j++){%>
											<option value="<%= j+1 %>"><%= j+1 %></option><% } %> 
										</select>
										<input type="submit" value="変更" />
									</form>
									<form action="<%= contextPath %>/orderCus/CartEditServlet" method="post" style="display:inline;">
										<input type="hidden" name="num" value="<%= i+1 %>" /> 
										<input type="submit" value="削除" />
									</form>
								</td>
							</tr>
							<% total_price = total_price + (item.getPrice() * oi.getOrders()); %>
							<% } %>
						</table>
					</div>
					<div id="goukei">
						合計<%= total_price %>円
					</div>
					<div id="fom">
						<form action="<%= contextPath %>/orderCus/CartInfoServlet" method="post" >
							<input type="submit" value="この内容でレジに進む" id="bot" />
						</form>
					</div>
					<div id="add">
						追加注文は←左側メニューからどうぞ！
					</div>
				</div>
			</div>
		</div>
	</body>
</html>
<%}%>